/*
Abstract:
  Format tools definitions

Last changed:
  $Id: format.h 82 2009-12-08 20:53:44Z vitamin.caig $

Author:
  (C) Vitamin/CAIG/2001

  This file is the part of Textator project
*/
#ifndef __FORMAT_H_DEFINED__
#define __FORMAT_H_DEFINED__

#include "tools.h"

template<class S>
class Formatter : private NonInstantiable
{
public:
  template<class P1>
  static S Process(const S& fmt, const P1& p1)
  {
    S res(fmt);
    InsParam(res, 1, p1);
    return res;
  }
  template<class P1, class P2>
  static S Process(const S& fmt, const P1& p1, const P2& p2)
  {
    S res(fmt);
    InsParam(res, 1, p1);
    InsParam(res, 2, p2);
    return res;
  }
  template<class P1, class P2, class P3>
  static S Process(const S& fmt, const P1& p1, const P2& p2, const P3& p3)
  {
    S res(fmt);
    InsParam(res, 1, p1);
    InsParam(res, 2, p2);
    InsParam(res, 3, p3);
    return res;
  }
  template<class P1, class P2, class P3, class P4>
  static S Process(const S& fmt, const P1& p1, const P2& p2, const P3& p3, const P4& p4)
  {
    S res(fmt);
    InsParam(res, 1, p1);
    InsParam(res, 2, p2);
    InsParam(res, 3, p3);
    InsParam(res, 4, p4);
    return res;
  }
  template<class P1, class P2, class P3, class P4, class P5>
  static S Process(const S& fmt, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5)
  {
    S res(fmt);
    InsParam(res, 1, p1);
    InsParam(res, 2, p2);
    InsParam(res, 3, p3);
    InsParam(res, 4, p4);
    InsParam(res, 5, p5);
    return res;
  }
private:
  template<class P>
  static void InsParam(S& str, std::size_t num, const P& param)
  {
    S pattern(2, '$');
    pattern[1] = static_cast<typename S::value_type>('0' + num);
    ReplaceInString<S>(str, pattern, ToString<S>::Convert(param));
  }
};

#endif //__FORMAT_H_DEFINED__
